package cn.liulin.java8.parallel;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * cn.liulin.java8.parallel$
 *
 * @author ll
 * @date 2021-11-15 17:35:17
 **/
public class ContentMain {
    public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
        PersonContent personContent = new PersonContent();
        personContent.setAge(11);
        personContent.setName("ZHANGSAN");
        System.out.println(JSON.toJSONString(personContent));
        Class<? extends BaseContent> personContentClass = PersonContent.class;
        BaseContent baseContent = JSON.parseObject("{\"age\":11,\"name\":\"ZHANGSAN\"}", personContentClass);
        Class<? extends BaseContent> aClass = baseContent.getClass();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            boolean annotationPresent = declaredField.isAnnotationPresent(MyNotNull.class);
            Object o = declaredField.get(baseContent);
            System.out.println(JSON.toJSONString(o));
            if (annotationPresent) {
                System.out.println(JSON.toJSONString(o));
            }
        }
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            declaredMethod.setAccessible(true);
            boolean annotationPresent = declaredMethod.isAnnotationPresent(MyNotNull.class);
            String name = declaredMethod.getName();
            if (name.contains("get")) {
                Object invoke = declaredMethod.invoke(baseContent);
                System.out.println(JSON.toJSONString(invoke));
            }
        }

    }
}
